
package com.rs.yyds.service.impl;

import com.rs.yyds.bean.SysConfig;
import com.rs.yyds.mapper.SysConfigMapper;
import com.rs.yyds.service.SysConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysConfigServiceImpl implements SysConfigService {
    @Resource
    private SysConfigMapper sysConfigMapper;


    @Override
    public List<SysConfig> getConfigList() {
        return sysConfigMapper.getConfigList();
    }

    @Override
    public Map<String, String> getSysConfigToMap() {
        List<SysConfig> allList = this.getConfigList();
        Map<String,String> map = new HashMap<>();
        for (SysConfig config : allList) {
            map.put(config.getJkey(),config.getJvalue());
        }
        return map;
    }

    @Override
    public String getValue(String key) {
        return sysConfigMapper.findValue(key);
    }

    @Override
    public void update(Map<String, String> params, HttpServletRequest request) {
        for(Map.Entry entry : params.entrySet()){
            sysConfigMapper.update((String)entry.getKey(),(String)entry.getValue());
            }
    }
    @Override
    public String getMysqlVersion() {
        return sysConfigMapper.getMysqlVersion();
    }
}
